package com.tz.hotelmanager.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tz.hotelmanager.domain.Bill;
import com.tz.hotelmanager.domain.BillExample;
import com.tz.hotelmanager.mapper.impl.BillMapperImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@RestController()
@RequestMapping("/bill/")
public class BillController {
  @Autowired
  BillMapperImpl billMapperImpl;

  @PostMapping(value = "getBill")
  public String getBill(@RequestBody JSONObject jsonparm, HttpServletRequest request, HttpSession session) {
    JSONObject result = new JSONObject();
    List<Bill> bills = billMapperImpl.selectByExample(new BillExample());
    JSONArray jsonArray = new JSONArray();
    for (Bill bill : bills) {
      jsonArray.add(JSONObject.parse(bill.toString()));
    }
    result.put("data", jsonArray);
    return result.toJSONString();
  }

  @PostMapping(value = "addBill")
  public String addBill(@RequestBody JSONObject jsonparm, HttpServletRequest request, HttpSession session) {
    // TODO: process POST request
    JSONObject result = new JSONObject();
    result.put("DSDS", 123);
    return result.toJSONString();
  }

  @PostMapping(value = "delBill")
  public String delBill(@RequestBody JSONObject jsonparm, HttpServletRequest request, HttpSession session) {
    // TODO: process POST request
    JSONObject result = new JSONObject();
    result.put("DSDS", 123);
    return result.toJSONString();
  }

  @PostMapping(value = "updateBill")
  public String updateBill(@RequestBody JSONObject jsonparm, HttpServletRequest request, HttpSession session) {
    // TODO: process POST request
    JSONObject result = new JSONObject();
    result.put("DSDS", 123);
    return result.toJSONString();
  }
}